home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / FetchNews 1.0.0b / source / TCPTypes.unit < prev   
Encoding:
Text File  |  1993-02-15  |  10.0 KB  |  441 lines  |  [TEXT/PJMM]

  1. unit TCPTypes;
  2.  
  3. { TCPTypes © Peter Lewis, Oct 1991 }
  4. { This source is Freeware }
  5.  
  6. interface
  7.  
  8. { MacTCP return Codes in the range -23000 through -23049 }
  9.     const
  10.         inProgress = 1;                            { I/O in progress }
  11.  
  12.         ipBadLapErr = -23000;                    { bad network configuration }
  13.         ipBadCnfgErr = -23001;                { bad IP configuration error }
  14.         ipNoCnfgErr = -23002;                    { missing IP or LAP configuration error }
  15.         ipLoadErr = -23003;                    { error in MacTCP load }
  16.         ipBadAddr = -23004;                    { error in getting address }
  17.         connectionClosing = -23005;            { connection is closing }
  18.         invalidLength = -23006;
  19.         connectionExists = -23007;            { request conflicts with existing connection }
  20.         connectionDoesntExist = -23008;        { connection does not exist }
  21.         insufficientResources = -23009;        { insufficient resources to perform request }
  22.         invalidStreamPtr = -23010;
  23.         streamAlreadyOpen = -23011;
  24.         connectionTerminated = -23012;
  25.         invalidBufPtr = -23013;
  26.         invalidRDS = -23014;
  27.         invalidWDS = -23014;
  28.         openFailed = -23015;
  29.         commandTimeout = -23016;
  30.         duplicateSocket = -23017;
  31.  
  32. { Error codes from internal IP functions }
  33.         ipDontFragErr = -23032;                { Packet too large to send w/o fragmenting }
  34.         ipDestDeadErr = -23033;                { destination not responding }
  35.         ipNoFragMemErr = -23036;            { no memory to send fragmented pkt }
  36.         ipRouteErr = -23037;                    { can't route packet off-net }
  37.  
  38.         nameSyntaxErr = -23041;
  39.         cacheFault = -23042;
  40.         noResultProc = -23043;
  41.         noNameServer = -23044;
  42.         authNameErr = -23045;
  43.         noAnsErr = -23046;
  44.         dnrErr = -23047;
  45.         outOfMemory = -23048;
  46.  
  47.     const
  48.         CTRUE = $FF;
  49.         CFALSE = $00;
  50.  
  51.     type
  52.         CBOOLEAN = signedByte;
  53.         ip_addr = longInt;
  54.         tcp_port = integer;
  55.         udp_port = integer;
  56.         StreamPtr = ptr;
  57.  
  58.     type
  59.         wdsType = record            { Write block for TCP driver. }
  60.                 size: integer;                { Number of bytes. }
  61.                 buffer: Ptr;                { Pointer to bytes. }
  62.                 term: integer;                { Zero for end of blocks. }
  63.             end;
  64.         wdsPtr = ^wdsType;
  65.  
  66.         hostInfo = record
  67.                 rtnCode: longInt;
  68.                 rtnHostName: str255;
  69.                 addrs: array[1..4] of longInt;
  70.             end;
  71.         hostInfoPtr = ^hostInfo;
  72.  
  73.     const { csCodes for the TCP driver: }
  74.         TCPcsGetMyIP = 15;
  75.         ipctlLAPStats = 19;
  76.         TCPcsCreate = 30;
  77.         TCPcsPassiveOpen = 31;
  78.         TCPcsActiveOpen = 32;
  79. {    TCPcsActOpenWithData = 33;}
  80.         TCPcsSend = 34;
  81.         TCPcsNoCopyRcv = 35;
  82.         TCPcsRcvBfrReturn = 36;
  83.         TCPcsRcv = 37;
  84.         TCPcsClose = 38;
  85.         TCPcsAbort = 39;
  86.         TCPcsStatus = 40;
  87.         TCPcsExtendedStat = 41;
  88.         TCPcsRelease = 42;
  89.         TCPcsGlobalInfo = 43;
  90.  
  91.         UDPcsCreate = 20;
  92.         UDPcsRead = 21;
  93.         UDPcsBfrReturn = 22;
  94.         UDPcsWrite = 23;
  95.         UDPcsRelease = 24;
  96.         UDPcsMaxMTUSize = 25;
  97.         UDPcsStatus = 26;
  98.         UDPcsMultiCreate = 27;
  99.         UDPcsMultiSend = 28;
  100.         UDPcsMultiRead = 29;
  101.         UDPcsCtlMax = 29;
  102.  
  103.     type
  104.         TCPEventCode = integer;
  105.     const
  106.         TEC_Closing = 1;
  107.         TEC_ULPTimeout = 2;
  108.         TEC_Terminate = 3;
  109.         TEC_DataArrival = 4;
  110.         TEC_Urgent = 5;
  111.         TEC_ICMPReceived = 6;
  112.         TEC_last = 32767;
  113.  
  114.     type
  115.         UDPEventCode = integer;
  116.     const
  117.         UDPDataArrival = 1;
  118.         UDPICMPReceived = 2;
  119.         lastUDPEvent = 32767;
  120.  
  121.     type
  122.         TCPTerminateReason = integer;
  123.     const {TCPTerminateReasons: }
  124.         TTR_RemoteAbort = 2;
  125.         TTR_NetworkFailure = 3;
  126.         TTR_SecPrecMismatch = 4;
  127.         TTR_ULPTimeoutTerminate = 5;
  128.         TTR_ULPAbort = 6;
  129.         TTR_ULPClose = 7;
  130.         TTR_ServiceError = 8;
  131.         TTR_last = 32767;
  132.  
  133.     type
  134.         TCPNotifyProc = procPtr;
  135. { procedure TCPNotifyProc(tcpStream:StreamPtr; event:TCPEventCode; userDataPtr:ptr; }
  136. {                                   terminReason:TCPTerminateReason; icmpMsg:ICMPReportPtr); }
  137.  
  138.     type
  139.         TCPIOCompletionProc = procPtr;
  140. { C procedure TCPIOCompletionProc(iopb:TCPControlBlockPtr); - WHY IS THIS A C PROC???? }
  141.  
  142.     type
  143.         UDPNotifyProc = procPtr;
  144. { procedure UDPProc(udpStream:StreamPtr ; eventCode:integer;userDataPtr:ptr; icmpMsg:ICMPReportPtr) }
  145.  
  146.     type
  147.         UDPIOCompletionProc = procPtr;
  148. {procedure UDPIOCompletionProc(iopb:UDPiopb Ptr) }
  149.  
  150.     type
  151.         UDPCreatePB = record { for create and release calls }
  152.                 rcvBuff: Ptr;
  153.                 rcvBuffLen: longInt;
  154.                 notifyProc: UDPNotifyProc;
  155.                 localport: integer;
  156.                 userDataPtr: ptr;
  157.                 endingPort: udp_port;
  158.             end;
  159.  
  160.     type
  161.         UDPSendPB = record
  162.                 reserved: integer;
  163.                 remoteIP: longInt;
  164.                 remotePort: udp_port;
  165.                 wds: wdsPtr;
  166.                 checkSum: signedByte;
  167.                 sendLength: integer;
  168.                 userDataPtr: ptr;
  169.                 localPort: udp_port;
  170.             end;
  171.  
  172.     type
  173.         UDPReceivePB = record
  174.                 timeOut: integer;
  175.                 remoteIP: longInt;
  176.                 remotePort: integer;
  177.                 rcvBuff: ptr;
  178.                 rcvBuffLen: integer;
  179.                 secondTimeStamp: integer;
  180.                 userDataPtr: ptr;
  181.                 destHost: ip_addr;
  182.                 destPort: udp_port;
  183.             end;
  184.  
  185.     type
  186.         UDPMTUPB = record
  187.                 mtuSize: integer;
  188.                 remoteIP: ip_addr;
  189.                 userDataPtr: ptr;
  190.             end;
  191.  
  192.     type
  193.         UDPControlBlock = record
  194.                 fill12: array[1..6] of integer;
  195.                 ioCompletion: UDPIOCompletionProc;
  196.                 ioResult: integer;
  197.                 ioNamePtr: stringPtr;
  198.                 ioVRefNum: integer;
  199.                 ioCRefNum: integer;
  200.                 csCode: integer;
  201.                 udpStream: streamPtr;
  202.                 case integer of
  203.                     UDPcsCreate: (
  204.                             create: UDPCreatePB
  205.                     );
  206.                     UDPcsWrite: (
  207.                             send: UDPSendPB
  208.                     );
  209.                     UDPcsRead: (
  210.                             receive: UDPReceivePB
  211.                     );
  212.                     UDPcsBfrReturn: (
  213.                             return: UDPReceivePB
  214.                     );
  215.                     UDPcsMaxMTUSize: (
  216.                             mtu: UDPMTUPB
  217.                     );
  218.             end;
  219.  
  220.     const { Validity Flags }
  221.         timeOutValue = $80;
  222.         timeOutAction = $40;
  223.         typeOfService = $20;
  224.         precedence = $10;
  225.  
  226.     const { TOSFlags }
  227.         lowDelay = $01;
  228.         throughPut = $02;
  229.         reliability = $04;
  230.  
  231.     type
  232.         TCPCreatePB = packed record
  233.                 rcvBuff: ptr;
  234.                 rcvBuffLen: longInt;
  235.                 notifyProc: TCPNotifyProc;
  236.                 userDataPtr: ptr;
  237.             end;
  238.  
  239.         TCPOpenPB = packed record
  240.                 ulpTimeoutValue: byte;
  241.                 ulpTimeoutAction: byte;
  242.                 validityFalgs: byte;
  243.                 commandTimeoutValue: byte;
  244.                 remoteHost: ip_addr;
  245.                 remotePort: tcp_port;
  246.                 localHost: ip_addr;
  247.                 localPort: tcp_port;
  248.                 tosFlags: byte;
  249.                 precedence: byte;
  250.                 dontFrag: CBOOLEAN;
  251.                 timeToLive: byte;
  252.                 security: byte;
  253.                 optionCnt: byte;
  254.                 options: array[0..39] of byte;
  255.                 userDataPtr: ptr;
  256.             end;
  257.  
  258.         TCPSendPB = packed record
  259.                 ulpTimeoutValue: byte;
  260.                 ulpTimeoutAction: byte;
  261.                 validityFalgs: byte;
  262.                 pushFalg: byte;
  263.                 urgentFlag: CBOOLEAN;
  264.                 wds: wdsptr;
  265.                 sendFree: longInt;
  266.                 sendLength: integer;
  267.                 userDataPtr: ptr;
  268.             end;
  269.  
  270.         TCPReceivePB = packed record
  271.                 commandTimeoutValue: byte;
  272.                 filler: byte;
  273.                 markFlag: CBOOLEAN;
  274.                 urgentFlag: CBOOLEAN;
  275.                 rcvBuff: ptr;
  276.                 rcvBuffLength: integer;
  277.                 rdsPtr: ptr;
  278.                 rdsLength: integer;
  279.                 secondTimeStanmp: integer;
  280.                 userDataPtr: ptr;
  281.             end;
  282.  
  283.         TCPClosePB = packed record
  284.                 ulpTimeoutValue: byte;
  285.                 ulpTimeoutAction: byte;
  286.                 validityFlags: byte;
  287.                 userDataPtrX: ptr;   { Thats mad!  Its not on a word boundary! Parhaps a documentation bug??? }
  288.             end;
  289.  
  290.         HistoBucket = packed record
  291.                 value: integer;
  292.                 counter: longInt;
  293.             end;
  294.  
  295.     const
  296.         NumOfHistoBuckets = 7;
  297.  
  298.     type
  299.         TCPConnectionStats = packed record
  300.                 dataPktsRcvd: longInt;
  301.                 dataPktsSent: longInt;
  302.                 dataPktsResent: longInt;
  303.                 bytesRcvd: longInt;
  304.                 bytesRcvdDup: longInt;
  305.                 bytesRcvdPastWindow: longInt;
  306.                 bytesSent: longInt;
  307.                 bytesResent: longInt;
  308.                 numHistoBuckets: integer;
  309.                 sentSizeHisto: array[1..NumOfHistoBuckets] of HistoBucket;
  310.                 lastRTT: integer;
  311.                 tmrRTT: integer;
  312.                 rttVariance: integer;
  313.                 tmrRTO: integer;
  314.                 sendTries: byte;
  315.                 sourceQuenchRcvd: byte;
  316.             end;
  317.         TCPConnectionStatsPtr = ^TCPConnectionStats;
  318.  
  319.         TCPStatusPB = packed record
  320.                 ulpTimeoutValue: byte;
  321.                 ulpTimeoutAction: byte;
  322.                 unused: longInt;
  323.                 remoteHost: ip_addr;
  324.                 remotePort: tcp_port;
  325.                 localHost: ip_addr;
  326.                 localPort: tcp_port;
  327.                 tosFlags: byte;
  328.                 precedence: byte;
  329.                 connectionState: byte;
  330.                 filler: byte;
  331.                 sendWindow: integer;
  332.                 rcvWindow: integer;
  333.                 amtUnackedData: integer;
  334.                 amtUnreadData: integer;
  335.                 securityLevelPtr: ptr;
  336.                 sendUnacked: longInt;
  337.                 sendNext: longInt;
  338.                 congestionWindow: longInt;
  339.                 rcvNext: longInt;
  340.                 srtt: longInt;
  341.                 lastRTT: longInt;
  342.                 sendMaxSegSize: longInt;
  343.                 connStatPtr: TCPConnectionStatsPtr;
  344.                 userDataPtr: ptr;
  345.             end;
  346.  
  347.         TCPAbortPB = packed record
  348.                 userDataPtr: ptr;
  349.             end;
  350.  
  351.         TCPParam = packed record
  352.                 tcpRtoA: longInt;
  353.                 tcpRtoMin: longInt;
  354.                 tcpRtoMax: longInt;
  355.                 tcpMaxSegSize: longInt;
  356.                 tcpMaxConn: longInt;
  357.                 tcpMaxWindow: longInt;
  358.             end;
  359.         TCPParamPtr = ^TCPParam;
  360.  
  361.         TCPStats = packed record
  362.                 tcpConnAttempts: longInt;
  363.                 tcpConnOpened: longInt;
  364.                 tcpConnAccepted: longInt;
  365.                 tcpConnClosed: longInt;
  366.                 tcpConnAborted: longInt;
  367.                 tcpOctetsIn: longInt;
  368.                 tcpOctetsOut: longInt;
  369.                 tcpOctetsInDup: longInt;
  370.                 tcpOctetsRetrans: longInt;
  371.                 tcpInputPackets: longInt;
  372.                 tcpOutputPkts: longInt;
  373.                 tcpDupPkts: longInt;
  374.                 tcpRetransPkts: longInt;
  375.             end;
  376.         TCPStatsPtr = ^TCPStats;
  377.  
  378.         StreamPtrArray = array[1..1000] of StreamPtr;
  379.         StreamPtrArrayPtr = ^StreamPtrArray;
  380.  
  381.         TCPGlobalInfoPB = packed record
  382.                 tcpParamp: TCPParamPtr;
  383.                 tcpStatsp: TCPStatsPtr;
  384.                 tcpCDBTable: StreamPtrArrayPtr;
  385.                 userDataPtr: ptr;
  386.                 maxTCPConnections: integer;
  387.             end;
  388.  
  389.         TCPGetMyIPPB = packed record
  390.                 ourAddress: ip_addr;
  391.                 ourNetMask: longInt;
  392.             end;
  393.  
  394.         TCPControlBlock = record
  395.                 qLink: QElemPtr;
  396.                 qType: INTEGER;
  397.                 ioTrap: INTEGER;
  398.                 ioCmdAddr: Ptr;
  399.                 ioCompletion: TCPIOCompletionProc; {completion routine, or NIL if none}
  400.                 ioResult: OSErr; {result code}
  401.                 ioNamePtr: StringPtr;
  402.                 ioVRefNum: INTEGER;
  403.                 ioCRefNum: INTEGER; {device refnum}
  404.                 case csCode : integer of
  405.                     TCPcsGetMyIP: (
  406.                             getmyip: TCPGetMyIPPB;
  407.                     );
  408.                     0: (
  409.                             tcpStream: StreamPtr;
  410.                             case integer of
  411.                                 TCPcsCreate: (
  412.                                         create: TCPCreatePB
  413.                                 );
  414.                                 TCPcsActiveOpen, TCPcsPassiveOpen: (
  415.                                         open: TCPOpenPB;
  416.                                 );
  417.                                 TCPcsSend: (
  418.                                         send: TCPSendPB;
  419.                                 );
  420.                                 TCPcsNoCopyRcv, TCPcsRcvBfrReturn, TCPcsRcv: (
  421.                                         receive: TCPReceivePB;
  422.                                 );
  423.                                 TCPcsClose: (
  424.                                         close: TCPClosePB;
  425.                                 );
  426.                                 TCPcsAbort: (
  427.                                         abort: TCPAbortPB;
  428.                                 );
  429.                                 TCPcsStatus: (
  430.                                         status: TCPStatusPB;
  431.                                 );
  432.                                 TCPcsGlobalInfo: (
  433.                                         globalInfo: TCPGlobalInfoPB
  434.                                 );
  435.                     );
  436.             end;
  437.         TCPControlBlockPtr = ^TCPControlBlock;
  438.  
  439. implementation
  440.  
  441. end.